package com.content.management.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.content.management.dao.DictionaryDirectoryDao;
import com.content.management.domain.entity.DictionaryDirectory;
import com.content.management.service.DictionaryDirectoryService;
import com.content.management.util.enums.DirectoryFlag;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * <p>
 * 数据字典目录（主键id能用于业务） 服务实现类
 * </p>
 *
 * @author xinghu
 * @since 2020-04-04
 */
@Service
public class DictionaryDirectoryServiceImpl extends ServiceImpl<DictionaryDirectoryDao, DictionaryDirectory> implements DictionaryDirectoryService {


	@PostConstruct
	public void init() {
		for (DirectoryFlag value : DirectoryFlag.values()) {
			DictionaryDirectory directory = this.lambdaQuery().eq(DictionaryDirectory::getDirectoryFlag, value.getFlag()).one();
			if (Objects.isNull(directory)) {
				directory = new DictionaryDirectory();
				directory.setDirectoryFlag(value.getFlag());
				directory.setDirectoryName(value.getName());
				directory.setCreateUserId(0L);
				directory.setUpdateUserId(0L);
				directory.setRemark("init");
				directory.setCreateUserName("");
				directory.setUpdateUserName("");
				directory.setCreateTime(LocalDateTime.now());
				directory.setUpdateTime(LocalDateTime.now());
				this.save(directory);
			}
		}
	}

}
